@ECHO OFF

rem ==================================================
rem TESTED ON: icu-4.6.1.
rem REQUIRES: cygwin: sed, rm
rem           visual studio 2010
rem PATH: sed
rem HOWTO: readme.html
rem ==================================================

rem =====SETTINGS====================================

rem Library architecture, possible values: Win32, x64
set ARCH=Win32

rem Build debug or release version, possible values: Debug, Release
set BUILD_TYPE=Debug

rem Building ICU static on Windows is really painful... (c)

rem ICU 4.6+ builds only on Visual Studio 2010.

rem Visual Studio path
set VC_PATH=C:\Program Files (x86)\Microsoft Visual Studio 10.0

rem Path to .bat utils, for example vs9tovs8.bat
set UTILS_PATH=%CD%

rem ICU sources path
set ICU_SRC_PATH=%CD%\src\icu-4.6.1

rem Directory where icu will be installed
set INSTALL_ROOT=%CD%

rem Path to return after compilation
set RETURN_PATH=%CD%

rem ==================================================

set INSTALL_PATH=%INSTALL_ROOT%\vc_10\%ARCH%\%BUILD_TYPE%\Dynamic\icu


rem Removing previous build results.
rm -rfd "%ICU_SRC_PATH%\bin*"
rm -rfd "%ICU_SRC_PATH%\lib*"
rmdir /S /Q "%ICU_SRC_PATH%\include*"


rem http://msdn.microsoft.com/en-us/library/x4d2c09s(v=VS.80).aspx
if %ARCH% == Win32 (
    call "%VC_PATH%\VC\bin\vcvars32.bat"
) else (
    call "%VC_PATH%\VC\vcvarsall.bat" x86_amd64
)


cd "%ICU_SRC_PATH%\source"

rem see readme.html
sed -b -i "s/define U_USING_ICU_NAMESPACE 1/define U_USING_ICU_NAMESPACE 0/" common/unicode/uversion.h


cd allinone
msbuild allinone.sln /t:rebuild /p:Configuration=%BUILD_TYPE%;Platform=%ARCH%



if %ARCH% == Win32 (
    set BIN_DIR=bin
    set LIB_DIR=lib
) else (
    set BIN_DIR=bin64
    set LIB_DIR=lib64
)


set PATH=%ICU_SRC_PATH%\%BIN_DIR%;%PATH%

rem tests will fail if executed not from their dirs
cd "%ICU_SRC_PATH%\source\test\intltest\%ARCH%\%BUILD_TYPE%"
intltest.exe

cd "%ICU_SRC_PATH%\source\test\cintltst\%ARCH%\%BUILD_TYPE%"
cintltst.exe

cd "%ICU_SRC_PATH%\source\test\iotest\%ARCH%\%BUILD_TYPE%"
iotest.exe


echo d | xcopy "%ICU_SRC_PATH%\%BIN_DIR%" "%INSTALL_PATH%\bin" /e /i /s /y
echo d | xcopy "%ICU_SRC_PATH%\%LIB_DIR%" "%INSTALL_PATH%\lib" /e /i /s /y
echo d | xcopy "%ICU_SRC_PATH%\include" "%INSTALL_PATH%\include" /e /i /s /y
echo f | xcopy "%ICU_SRC_PATH%\source\data\out\icudt*.dat" "%INSTALL_PATH%\bin"


cd "%RETURN_PATH%"

@ECHO ON
